package com.sxy.web.request;
/**
 * @author 宋鑫宇
 * @version 1.0
 * 请求转发 forward使用
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/req4")
public class RequestDemo04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("demo4...");

        //存储数据
        request.setAttribute("msg","hello");

        //请求转发特点：
        //      1.浏览器地址栏路径不发生变化
        //      2.只能转发到当前服务器的内部资源
        //      3.一次请求，可以在转发的资源间使用request共享数据
        request.getRequestDispatcher("/req3").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
